package com.example.windowdemo.window.composite;

import android.view.View;

import com.example.windowdemo.callback.WindowComponent;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: njb
 * @date: 2023/8/3 11:18
 * @desc:
 */
public class WindowComposite implements WindowComponent {
    private List<WindowComponent> components;

    public WindowComposite() {
        components = new ArrayList<>();
    }

    public void add(WindowComponent component) {
        components.add(component);
    }

    public void remove(WindowComponent component) {
        components.remove(component);
    }

    @Override
    public void show() {
        for (WindowComponent component : components) {
            component.show();
        }
    }

    @Override
    public void hide() {
        for (WindowComponent component : components) {
            component.hide();
        }
    }

    @Override
    public void setSize(int width, int height) {
        for (WindowComponent component : components) {
            component.setSize(width, height);
        }
    }

    @Override
    public void setPosition(int x, int y) {
        for (WindowComponent component : components) {
            component.setPosition(x, y);
        }
    }

    @Override
    public void setGravity(int gravity) {
        for (WindowComponent component : components) {
            component.setGravity(gravity);
        }
    }

    @Override
    public void setData(Object data) {
        for (WindowComponent component : components) {
            component.setData(data);
        }
    }

    @Override
    public void addView(View view) {
        for (WindowComponent component : components) {
            component.addView(view);
        }
    }
}
